import {
  axios
} from '@/utils/request'
import my from './my/my'
import constantFile from './my/constantFile'
import reqwest from 'reqwest'
import axiosAll from 'axios'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'

const api = {
  user: '/user',
  role: '/role',
  service: '/service',
  permission: '/permission',
  permissionNoPager: '/permission/no-pager',
  orgTree: '/org/tree'
}

export default api

export function postTest(url, parameter) {
  return axios({
    url: url,
    method: 'post',
    data: parameter
  })
}
export function getUrl(url, parameter) {
  return axios({
    url: my.baseURL + url,
    method: 'get',
    params: parameter
  })
  
}
export function uploadUrl(url, formData) {
  var configs = {
		headers:{'Content-Type':'multipart/form-data','Authorization':Vue.ls.get(ACCESS_TOKEN)}
	}
  return axiosAll.post(my.baseURL + url,formData ,configs)
  
}
export function postAxiosUrl(url, parameter) {
  return axios({
    url: my.baseURL+url,
    method: 'post',
    data: parameter
  })
}
export function getAxiosUrl(url, parameter) {
  return axios({
    url: my.baseURL+url,
    method: 'get',
    data: parameter
  })
}
export function postUrl(url, parameter) { 
  return reqwest({
    contentType: 'application/json',
    type: 'json',
    url: my.baseURL + url,
    method: 'post',
    data: {
      ...parameter,
    }
  })}



export function getAllUser(parameter) {
  return axios({
    url: my.baseURL + constantFile.url.getAllUser,
    method: 'get',
    params: parameter
  })
}

export function getRoleList(parameter) {
  return axios({
    url: api.role,
    method: 'get',
    params: parameter
  })
}

export function getServiceList(parameter) {
  return axios({
    url: api.service,
    method: 'get',
    params: parameter
  })
}

export function getPermissions(parameter) {
  return axios({
    url: api.permissionNoPager,
    method: 'get',
    params: parameter
  })
}

export function getOrgTree(parameter) {
  return axios({
    url: api.orgTree,
    method: 'get',
    params: parameter
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveService(parameter) {
  return axios({
    url: api.service,
    method: parameter.id === 0 ? 'post' : 'put',
    data: parameter
  })
}
